#!/usr/bin/env python
# -*- coding: utf8 -*-
# title       :
# description :
# author      :'ShenMeng'

from PySide import QtGui, QtCore


class MoveWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(MoveWidget, self).__init__(parent)

        # 初始化参数
        self._move = False
        self._parent = parent
        self._margins = self._parent.layout().getContentsMargins()

        # 无边框透明
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowSystemMenuHint)
        # self.setAttribute(Qt.WA_TranslucentBackground)
        self.setWindowOpacity(0)
        self.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Fixed)
        self.maxNormal=False
        #self.setMinimumWidth(300)

    def mousePressEvent(self,event):
        if event.button() == QtCore.Qt.LeftButton:
            self._move = True
            self._parent.offset = event.pos()

    def mouseReleaseEvent(self, event):
        self._move = False

    def mouseMoveEvent(self,event):
        if self._move:
            mp = QtCore.QPoint()
            mp.setX(self._margins[0])
            mp.setY(self._margins[1])
            self._parent.move(event.globalPos()-self._parent.offset - mp)

    def mouseDoubleClickEvent(self, event):
        return
        # if(self.maxNormal):
        #     self._parent.showNormal()
        #     self.maxNormal= False
        # else:
        #     self._parent.showMaximized()
        #     self.maxNormal=  True

